import {
	mapState,
	mapMutations
} from 'vuex'
import { formatDateByTimestamp } from '@/utils/utils.js'
export default {
	data() {
		return {
			childrenList: [],
			recordId: '',
			infoType: true
		}
	},
	computed: {
		...mapState({
			appType: state => state.app.appType,
		}),
	},
	onLoad(options) {
		this.recordId = options.recordId;
		this.defaultChildren = options;
		if(options.types) {
			this.infoType = JSON.parse(options.types)
		}

		if (!this.$u.test.isEmpty(options)){
			this.childrenList.push(options);
		}
		this.getRecord()
	},
	onReady() {
		this.$refs.uForm.setRules(this.rules);
	},
	methods: {
		showClasses() {
			this.$refs.popupConpare.open();
		},
		confirm(res) {
			console.log(res);
			if (!this.$u.test.isEmpty(this.defaultChildren)){
				for (let index in res) {
					let has = false;
					let item = res[index];
					for (let cIndex in this.childrenList) {
						let cItem = this.childrenList[cIndex];
						if (item.id === cItem.id) {
							has = true;
						}
					}
					if (!has) {
						this.childrenList.push(item);
					}
				}
			} else {
				for (let index in res) {
					let item = res[index];
					if (this.childrenList.indexOf(item) === -1) {
						this.childrenList.push(item);
					}
				}
			}
		},
		
		childrenItemClick(index) {
			this.childrenList.splice(index, 1);
		},
		
		saveClick() {
			console.log(this.form);
			if (this.childrenList.length === 0) {
				this.$u.toast('请先选择宝宝');
				return;
			}
			this.$refs.uForm.validate(valid => {
				console.log(valid);
				if (valid) {
					this.addRecord();
					return;
				}
			});
		},
		
		addShow() {
			// return true
			return this.$u.test.isEmpty(this.recordId)
		}
	}
}
